const EventEmitter = require('events');
const {desktopCapturer} = require('electron')

const peer = new EventEmitter();

//我们这里模拟一下捕获桌面流的一个过程
async function getScreenStream(){
  const source = await desktopCapturer.getSources({types: ['screen']})

  navigator.webkitGetUserMedia({
    audio: false,
    video: {
      mandaory: {
        chromeMediaSource: 'desktop',
        chromeMediaSourceId: source[0].id,
        maxWidth: window.screen.width,
        maxHeight: window.screen.height
      }
    }
  }, (stream) => {
    peer.emit('add-stream', stream);
  }, (err)=>{
    //handle error
    console.error(err);
  });
}

getScreenStream();

module.exports = peer;
